var app = new Vue({
    el: '#app',
    data: {
        list: [
            {
                id: 1,
                name: '苹果',
                price: 10,
                count: 1
            },
            {
                id: 2,
                name: '橘子',
                price: 14,
                count: 1
            },
            {
                id: 3,
                name: '梨子',
                price: 16,
                count: 1
            }
        ],
        picked: []
    },
    computed: {
       totalPrice: function() {
           var total = 0;
           for(var i=0; i<this.list.length; i++) {
               var item = this.list[i];
               total += item.price * item.count;
           }
           return total;
       }
    },
    methods: {
        handleReduce: function(index) {
            if(this.list[index].count === 1) return;
            this.list[index].count--;
        },
        handleAdd: function(index) {
            this.list[index].count++;
        },
        handleRemove: function(index) {
            this.list.splice(index, 1);
        },
    }

})